/*
 * @Author: your name
 * @Date: 2021-08-20 08:49:46
 * @LastEditTime: 2021-08-31 15:14:33
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue-cli-vue2\src\store\index.js
 */
true;

import Vue from "vue";
import Vuex from "vuex";
import getters from "./getters";
import plugins from "./plugins";

/**
 * @description:实现自动化导入模块
 * @param {directory} 读取文件的路径
 * @param {useSubdirectories} 是否遍历文件的子目录
 * @param {regExp} 匹配文件的正则
 * @return {*}
 */
const modulesFiles = require.context("./modules", true, /\.js$/);

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
	// set './app.js' => 'app'
	const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, "$1");
	const value = modulesFiles(modulePath);
	modules[moduleName] = value.default;
	return modules;
}, {});

Vue.use(Vuex);

export default new Vuex.Store({
	// strict: strict: process.env.NODE_ENV !== 'production',//严格模式会深度监测状态树来检测不合规的状态变更——请确保在发布环境下关闭严格模式，以避免性能损失。
	state: { test: 123, aaa: () => JSON.parse(localStorage.getItem("aaa")) },
	modules,
	getters,
	plugins,
});
